//
//  LEUnitView+LE.m
//  CreditAddressBook
//
//  Created by LE on 16/1/7.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "LEUnitView+LE.h"
#import "LEImagePicker.h"

@implementation LEUnitView (LE)
/**
 *  添加图片选择器LEUnitView
 *
 *  @param view  添加目标view
 *  @param block 添加完成后的block
 */
+ (LEUnitView *)imageScrollView:(UIView *)view controller:(UIViewController *)controller block:(void (^)(LEUnitView *unitView, LEUnitCell *cell, UIImage *image))block cellClick:(LECellClick)click {
    LEImagePicker *imagePicker = [LEImagePicker new];
    LEUnitView *unitView = [[LEUnitView alloc] initWithFrame:(CGRect){CGPointZero, view.frame.size}];
    [view addSubview:unitView];
    [unitView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero];
    
    CYWeakObject(weakUnitView, unitView);
    CYWeakObject(wController, controller);
    [unitView addButtonClick:^{
        [imagePicker showInController:wController handler:^(UIImage *image) {
            LEUnitCell *cell = [weakUnitView addNewUnit:image withName:@""];
            if (block) {
                block(weakUnitView, cell, image);
            }
        }];
    }];
    [unitView cellClick:click];
    return unitView;
}
@end
